package com.ruoyi.business.controller;

import com.ruoyi.business.domain.vo.IndexStatisticsVO;
import com.ruoyi.business.service.IBusCbsgrxxService;
import com.ruoyi.business.service.IBusCbsxxService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.system.service.ISysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 承包商工人信息Controller
 *
 * @author yaowei
 * @date 2021-06-30
 */
@Api(description = "首页")
@RestController
@RequestMapping("/business/index")
public class IndexController extends BaseController {
    /**
     * 数据字典-站库
     */
    public static final String DICT_ZK = "bus_zdxx";

    /**
     * 数据字典-单井
     */
    public static final String DICT_DJ = "bus_djxx";

    @Autowired
    private ISysDictDataService dictDataService;

    @Autowired
    private IBusCbsgrxxService busCbsgrxxService;

    @Autowired
    private IBusCbsxxService busCbsxxService;

    /**
     * 首页-承包商/工人/站库/单井数量统计
     */
    @ApiOperation("首页-承包商/工人/站库/单井数量统计")
    @GetMapping("/statistics")
    public IndexStatisticsVO statistics() {
        IndexStatisticsVO indexStatisticsVO = new IndexStatisticsVO();
        Long cbsCount = busCbsxxService.countAll();
        indexStatisticsVO.setCbsCount(cbsCount);
        // 在职人员总数
        Long ryCount = busCbsgrxxService.countAll();
        indexStatisticsVO.setRyCount(ryCount);
        // 站库数量
        List<SysDictData> zkList = dictDataService.selectDictDataByType(DICT_ZK);
        indexStatisticsVO.setZkCount((long) zkList.size());
        // 单井数量
        List<SysDictData> djList = dictDataService.selectDictDataByType(DICT_DJ);
        indexStatisticsVO.setDjCount((long) djList.size());
        return indexStatisticsVO;
    }
}
